<?php
class attachControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onInit(){
		
	}
	
	public function onDefault(){
		
	}
	
	public function onGet(){
		$id=get('id','i');
		$data=M("attach")->selectRow("id=".$id);
		$f_type=strtolower(trim(substr(strrchr($data['imgurl'], '.'), 1)));
		$file_name=basename($data['imgurl']);
		
		//$file_size=filesize($data['trueimgurl']);
		header("Content-type: application/octet-stream");
		//header("Accept-Ranges: bytes"); 
		//header("Accept-Length:".$file_size); 
		header("Content-Disposition: attachment; filename=".$file_name);
		echo file_get_contents($data['trueimgurl']); 
	}
	
	public function onGetImg(){
		$id=get('id','i');
		$data=M("attach")->selectRow("id=".$id);
		if(get('type')=='middle'){
			header("Location: ".$data['trueimgurl'].".middle.jpg");
		}elseif(get('type')=='base'){
			header("Location: ".$data['trueimgurl']);	
		}else{
			header("Location: ".$data['trueimgurl'].".small.jpg");
		}
	}
	
}
?>